package edu.gatech.asthma.ui_support.symptoms;

import edu.gatech.asthma.R;
import edu.gatech.asthma.ui_support.ResourceHelper;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageView;

/**
 * Click listener for symptoms list
 */
public class SymptomsClickListener implements OnItemClickListener, OnItemLongClickListener{
	boolean younger;	//a boolean value that tells if the childs age is 5 or greater
	int accent; 		//refers to accent color choice

	public SymptomsClickListener(boolean younger, int accent) {
		this.younger = younger;
		this.accent = accent;
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		//TODO remove all Log tags
		Context context = view.getContext();
		
		ImageView checkBox = (ImageView) view.findViewById(R.id.symptom_checkbox);
		
		/*position in the ListView DOES NOT correspond to position of the symptom in the resource string array
			the tag does (b/c ListView recycles and deletes unseen list items) */
		SymptomsListItem clickedItem = (SymptomsListItem) view.getTag();
		int itemId = clickedItem.getItemId();
		
		if (clickedItem.getIsChecked()) {
			checkBox.setImageResource(R.drawable.checkbox_no_check);
			clickedItem.setIsChecked(false);
		}
		else {
			checkBox.setImageResource(R.drawable.checkbox_check);
			clickedItem.setIsChecked(true);
			checkBox.setColorFilter(context.getResources().getColor(ResourceHelper.getColor("accent_color"+accent)));
		}
		
		if (younger)
			Log.d("UI","You selected " + context.getResources().getStringArray(R.array.symptoms_younger)[itemId]);
		else
			Log.d("UI","You selected " + context.getResources().getStringArray(R.array.symptoms_older)[itemId]);
	}

	
	@Override
	public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
		// Bring up help dialog on long click
		return false;
	}

}
